package jblip.util;

import java.util.ArrayList;
import java.util.List;

import jblip.resources.Update;

public abstract class UpdatesFilter {
  public static class UpdateNumberFilter extends UpdatesFilter {
    private final int lower_bound;
    public UpdateNumberFilter(final int lower_bound) {
      if (lower_bound < 0) {
        throw new IllegalArgumentException("Lower bound must be non-negative");
      }
      this.lower_bound = lower_bound;
    }
    @Override
    protected boolean filterUpdate(Update next) {
      return next.getId() <= lower_bound;
    }
  }
  
  public final Iterable<? extends Update> filter(
      final Iterable<? extends Update> updates) {
    List<Update> filtered_updates = new ArrayList<Update>();
    for (Update update : updates) {
      if (!filterUpdate(update)) {
        filtered_updates.add(update);
      }
    }
    return filtered_updates;
  }

  protected abstract boolean filterUpdate(Update next);
}
